package com.cropdoctor.controller;

import com.cropdoctor.common.Result;
import com.cropdoctor.model.po.CourseInfoPo;
import com.cropdoctor.model.vo.PublishCourseVO;
import com.cropdoctor.service.CommentService;
import com.cropdoctor.service.CourseService;
import com.cropdoctor.service.PostService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@Slf4j
@Api(tags = "专家端相关接口")
@RequestMapping("/expert")
public class ExpertController {

    @Autowired
    PostService postService;

    @Autowired
    CommentService commentService;

    @Autowired
    CourseService courseService;

    @PutMapping("/course")
    @ApiOperation("保存教学课程基本信息")
    public Result<String> saveCourse(@RequestBody CourseInfoPo courseInfoPo){
        return courseService.saveCourseInfo(courseInfoPo);
    }

    @DeleteMapping("/course/reEdit/{id}")
    @ApiOperation("保存教学课程基本信息")
    public Result<String> reEditCourse(@PathVariable Long id){
        return courseService.reEditCourse(id);
    }

    @GetMapping("/course")
    @ApiOperation("获取教学课程基本信息")
    public Result<List<CourseInfoPo>> getCourse(@RequestParam("auditStatus")String auditStatus){
        return courseService.getMyCourseInfo(auditStatus);
    }

    @GetMapping("/course/{courseId}/{index}")
    public Result<CourseInfoPo> getSingleCourseInfo(@PathVariable long courseId,@PathVariable String index){
        return courseService.getSingleCourseInfo(courseId,index);
    }

    @DeleteMapping("/course/{id}")
    @ApiOperation("删除教学课程信息")
    public Result<String> deleteCourse(@PathVariable long id){
        return courseService.deleteCourseInfo(id);
    }

    @PutMapping("/course/submit")
    @ApiOperation("提交教学课程待审核")
    public Result<String> submitCourse(@RequestBody CourseInfoPo courseInfoPo){
        return courseService.submitCourseInfo(courseInfoPo);
    }

    @PostMapping("/course/upload")
    @ApiOperation("教学课程审核通过后可发布")
    public Result<String> uploadCourse(@RequestBody CourseInfoPo courseInfoPo){
        return courseService.uploadCourse(courseInfoPo);
    }

    @DeleteMapping("/course/down/{courseId}")
    @ApiOperation("发布的课程可以下架")
    public Result<String> downCourse(@PathVariable long courseId){
        return courseService.removeCourse(courseId);
    }

    @PostMapping("/course/up/{courseId}")
    public Result<String> upCourse(@PathVariable long courseId){
        return courseService.upCourse(courseId);
    }

    @GetMapping("/publishCourse")
    @ApiOperation("查看自己发布过的课程")
    public Result<List<PublishCourseVO>> getUploadCourse(){
        return courseService.getUploadCourse();
    }

}


